<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表单验证</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <style>
        .valid,
        .form-group input:valid,
        .form-group textarea:valid {
            border-color: #429032;
            box-shadow: inset 5px 0 0 #429032;
        }

        .invalid,
        .form-group input:invalid,
        .form-group textarea:invalid {
            border-color: #D61D1D;
            box-shadow: inset 5px 0 0 #D61D1D;
        }

        .form-group {
            width: 32rem;
            padding: 1rem;
            border: 1px solid transparent;
        }

        .form-group:hover {
            border-color: #eee;
            -webkit-transition: border .2s;
            transition: border .2s;
        }

        .form-group label {
            display: block;
            font-weight: normal;
        }

        .form-group input,
        .form-group textarea {
            display: block;
            width: 100%;
            line-height: 2rem;
            padding: .5rem .5rem .5rem 1rem;
            border: 1px solid #ccc;
            outline: none;
        }
    </style>
</head>

<body>
    <div class="container">
        <pre>
    html5丰富了表单元素，提供了类似required,email,tel等表单元素属性。同样的，我们可以利用:valid和:invalid来做针对html5表单属性的校验。
        :required 伪类指定具有required 属性的表单元素
        :valid 伪类指定一个通过匹配正确的所要求的表单元素
        :invalid 伪类指定一个不匹配指定要求的表单元素
        </pre>
        <div class="row" style="margin-top: 2rem;">
            <form>
                <div class="form-group">
                    <label>name</label>
                    <input type="text" required placeholder="请输入名称">
                </div>
                <div class="form-group">
                    <label>email</label>
                    <input type="email" required placeholder="请输入邮箱">
                </div>
                <div class="form-group">
                    <label>homepage</label>
                    <input type="url" placeholder="请输入博客url">
                </div>
                <div class="form-group">
                    <label>Comments</label>
                    <textarea required></textarea>
                </div>
            </form>
        </div>
    </div>
</body>

</html>